import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../models/anniversary.dart';
import '../widgets/anniversary_countdown_card.dart';
import '../widgets/anniversary_list_item.dart';
import 'add_anniversary_page.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final today = DateTime.now();
    final dateStr = DateFormat('yyyy年MM月dd日 EEEE', 'zh_CN').format(today);
    const weather = '☀ 22°C';

    final anniversaries = [
      Anniversary(
        name: '恋爱纪念日',
        type: '恋爱',
        date: DateTime(today.year, today.month, today.day + 12),
        note: '',
        isRepeat: true,
        daysLeft: 12,
        daysPast: 0,
        iconCode: Icons.favorite.codePoint,
        colorValue: 0xFFFF6B35,
      ),
      Anniversary(
        name: '妈妈生日',
        type: '生日',
        date: DateTime(today.year, 6, 1),
        note: '',
        isRepeat: true,
        daysLeft: 22,
        daysPast: 0,
        iconCode: Icons.cake.codePoint,
        colorValue: 0xFFFF8E9E,
      ),
      Anniversary(
        name: '入职纪念日',
        type: '工作',
        date: DateTime(today.year - 1, 9, 1),
        note: '',
        isRepeat: false,
        daysLeft: -250,
        daysPast: 250,
        iconCode: Icons.work.codePoint,
        colorValue: 0xFF4A90E2,
      ),
    ];

    final nextAnniversary = anniversaries.first;

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(dateStr, style: const TextStyle(fontSize: 16, color: Color(0xFF333333))),
            Row(
              children: [
                const Icon(Icons.wb_sunny, color: Color(0xFFFF6B35)),
                const SizedBox(width: 4),
                Text(weather, style: const TextStyle(fontSize: 16, color: Color(0xFF333333))),
              ],
            ),
          ],
        ),
      ),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
            child: AnniversaryCountdownCard(data: nextAnniversary),
          ),
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
              ),
              child: ListView.separated(
                padding: const EdgeInsets.all(20),
                itemCount: anniversaries.length,
                separatorBuilder: (_, __) => const SizedBox(height: 12),
                itemBuilder: (context, index) {
                  final item = anniversaries[index];
                  return AnniversaryListItem(data: item);
                },
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: const Color(0xFFFF6B35),
        onPressed: () {
          Navigator.of(context).push(
            MaterialPageRoute(builder: (context) => const AddAnniversaryPage()),
          );
        },
        child: const Icon(Icons.add, color: Colors.white),
        tooltip: '添加纪念日',
      ),
    );
  }
} 